package com.example.forum.controller;

import com.example.forum.domain.Comment;
import com.example.forum.service.CommentService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class CommentController {
    private final Logger logger= LoggerFactory.getLogger(CommentController.class);
    @Autowired
    private CommentService commentService;

    //增加一个评论
    @RequestMapping("/addComment/{discussPostId}")
    public String addComment(@PathVariable("discussPostId") int discussPostId,Comment comment){
        try {
            commentService.addComment(comment);
        } catch (Exception e) {
            logger.error("添加评论错误:"+e.getMessage());
        }
        return "redirect:/discussPostInfo?id="+discussPostId;
    }
}
